package org.blade.personal.manager.codeGen.concre;

import java.util.List;

import javax.transaction.Transactional;

import org.blade.personal.dao.codegen.PdmColumnDao;
import org.blade.personal.dao.codegen.PdmTableDao;
import org.blade.personal.manager.codeGen.PdmTableManager;
import org.blade.personal.utils.Pager;
import org.blade.personal.utils.pdm.PdmColumn;
import org.blade.personal.utils.pdm.PdmTable;
import org.springframework.stereotype.Service;

@Service
@Transactional
public class ConcrePdmTableManager implements PdmTableManager {

	private PdmTableDao tableDao;
	
	private PdmColumnDao columnDao;
	
	@Override
	@Transactional
	public void saveTable(List<PdmTable> tables) {
		
		for(PdmTable table : tables){
			tableDao.save(table);
			this.saveColumn(table.getColumn());
		}
	}

	@Override
	@Transactional
	public void updateTable(PdmTable table) {
		tableDao.update(table);
		for(PdmColumn column: table.getColumn() ){
			this.updateColumn(column);
		}
	}

	@Override
	@Transactional
	public void saveColumn(List<PdmColumn> columns) {
		for(PdmColumn column : columns){
			System.out.println(column.getComment());
			columnDao.save(column);
		}
	}

	@Override
	@Transactional
	public void updateColumn(PdmColumn column) {
		columnDao.update(column);
	}

	@Override
	@Transactional
	public void findTable(Pager<PdmTable> pager,String id) {
		 tableDao.getTableByPackageId(id);
	}

	@Override
	@Transactional
	public void findColumn(Pager<PdmColumn> pager,String tableId) {
		 columnDao.getColumns(tableId);
	}

}
